package com.lym.controller;

import com.car.entity.SysUser;
import com.car.util.Result;
import com.car.vo.CarInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@CrossOrigin
@RequestMapping("client")
@RestController
public class ClientController {
    @Autowired
    private RestTemplate restTemplate;
    @PostMapping("addCarInfo")
    @ResponseBody
    public Result addCar(@RequestBody CarInfoVo carInfoVo){
        System.err.println(carInfoVo);
        Result result = restTemplate.postForEntity("http://car-base/addcar", carInfoVo, Result.class).getBody();
        return new Result(true,"返回成功");
    }
    //登录
    @PostMapping("login")
    @ResponseBody
    public Result Login(@RequestBody SysUser sysUser){
        System.err.println(sysUser);
        String token = restTemplate.postForEntity("http://car-base/Login", sysUser, String.class).getBody();
        return new Result(true,"返回成功",token);
    }
    public Result findBack(String appKey, HttpServletRequest request){
        return new Result(false,"服务中断。。。请重试！");
    }

}
